<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .demo-reg-container {
            width: 320px;
            height: 320px;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -160px; /* 一半高度 */
            margin-left: -160px; /* 一半宽度 */
        }

        .demo-reg-other .layui-icon { /* 这部分样式不需要修改 */
            position: relative;
            display: inline-block;
            margin: 0 2px;
            top: 2px;
            font-size: 26px;
        }

        body, html {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        body {
            /* 设置背景图片的路径和样式 */
            background-image: url('/img/1.jpg');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
        }

        .login-form-container {
            background-image: url('/img/2.jpg');
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
            background-color: rgba(255, 255, 255, 0.9); /* 设置登录表单的背景颜色和透明度 */
            border-radius: 15px;
            padding: 20px;
            height: 270px;
        }

        .demo-login-other .layui-icon {
            font-size: 20px; /* 调整图标的大小，可以根据需要适当调整数值 */
            margin-right: 10px; /* 增加图标之间的间距 */
        }
    </style>
    <link href="/layui/css/layui.css" rel="stylesheet"/>
</head>
<script src="/js/jquery-3.3.1.min.js" type="application/ecmascript"></script>
<script type="text/javascript" src="/layui/layui.js"></script>
<body>
<button  id="btn_submit">测试</button>
<div class="demo-reg-container login-form-container">
    <form class="layui-form">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="userName" value="" lay-verify="required" placeholder="用户名"
                           lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="userPassword" value="" lay-verify="required" placeholder="密   码"
                           lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <div class="layui-input-wrap">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-vercode"></i>
                            </div>
                            <input type="text" name="captcha" value="" lay-verify="required" placeholder="验证码"
                                   lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="https://www.oschina.net/action/user/captcha"
                                 onclick="this.src='x'+ new Date().getTime();">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                <a href="form.html#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>
            </div>
            <div class="layui-form-item demo-login-other">
                <label>社交账号登录</label>
                <span style="padding: 0 21px 0 6px;">
        <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color: #3492ed;"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color: #4daf29;"></i></a>
        <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a>
      </span>
                或 <a href="/enroll">注册帐号</a></span>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;
        $('#btn_submit').click(function(){
            $.ajax({
                url: "/user/addb",
                method: "POST",
                dataType: 'json',
                // data: {
                //   user:{
                //       userId:1,
                //       userName:2,
                //       passWord:3
                //   }
                // },
                success: function (data) {
                    alert(1);
                },
                error: function () {
                    alert("密码异常");
                }
            });
        });

        // 提交事件
        form.on('submit(demo-login)', function (data) {
            var field = data.field; // 获取表单字段值
            // 显示填写结果，仅作演示用
            // layer.alert(JSON.stringify(field), {
            //     title: '当前填写的字段值'
            // });
            // 此处可执行 Ajax 等操作
            $.ajax({
                url: "/login/index",
                method: "POST",
                dataType: 'json',
                contentType: "application/json;charsetset=UTF-8",
                cache: true,
                async: false,
                data: JSON.stringify(field),
                success: function (data) {
                    console.log(data.code);
                    if (data.code === 500) {
                        alert("账号名或密码错误");
                        return;
                    } else if (data.code === 300) {
                        alert("账号异常");
                        return;
                    }
                    window.location.href = "/login";
                },
                error: function () {
                    alert("密码异常");
                }
            });
            // …
            return false; // 阻止默认 form 跳转
        });
    });
</script>
</html>